﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="seotud_isikType", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(SeotudIsikType))]
    public class SeotudIsikTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISeotudIsikType clazz;
        
        public SeotudIsikTypeSerializer(ISeotudIsikType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tegevus");
            if (clazz.Tegevus!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_tegevus");
                Writer.WriteString(clazz.Tegevus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tegevus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("isiku_roll");
            if (clazz.IsikuRoll!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_isikuroll");
                Writer.WriteString(clazz.IsikuRoll.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuRoll");
            }
            Writer.WriteEndElement();
            if (clazz.VolitusteKpv!=null) {
                Writer.WriteStartElement("volituste_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.VolitusteKpv))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("isik");
            if (clazz.Isik!=null) {
                global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData(clazz.Isik);
                Writer.WriteTypeAttribute(metaIsik.TypeQualifiedName.Namespace, metaIsik.TypeQualifiedName.Name);
                metaIsik.NewSerializer(clazz.Isik).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isik");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="tegevus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>seotud_isikType>tegevus");
                }
                clazz.Tegevus = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XTegevus(Reader.ReadElementString("tegevus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>seotud_isikType>tegevus", Reader.LocalName);
            }
            if (Reader.LocalName=="isiku_roll") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>seotud_isikType>isiku_roll");
                }
                clazz.IsikuRoll = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XIsikuroll(Reader.ReadElementString("isiku_roll"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>seotud_isikType>isiku_roll", Reader.LocalName);
            }
            if (Reader.LocalName=="volituste_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>seotud_isikType>volituste_kpv");
                }
                clazz.VolitusteKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("volituste_kpv")).Value;
            }
            if (Reader.LocalName=="isik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>seotud_isikType>isik");
                }
                global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikType>(Reader, "isikType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Isik = metaIsik.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("isik");
                    metaIsik.NewSerializer(clazz.Isik).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>seotud_isikType>isik", Reader.LocalName);
            }
        }
    }
}
